package com.winit.cloudlink.mgmt.config;

import com.winit.cloudlink.spring.CloudlinkFactoryBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
@EnableConfigurationProperties(CloudlinkProperties.class)
public class CloudlinkAutoConfigure {

    @Bean(name = "cloudlink")
    public CloudlinkFactoryBean cloudlink(CloudlinkProperties config) {
        CloudlinkFactoryBean cloudlink = new CloudlinkFactoryBean();
        Properties properties = new Properties();
        properties.setProperty("appId", config.getAppId());
        properties.setProperty("appType", config.getAppType());
        properties.setProperty("zone", config.getZone());
        properties.setProperty("mq", config.getMq());
        properties.setProperty("owner", config.getOwner());
        properties.setProperty("appVersion", config.getAppVersion());
        properties.setProperty("organization", config.getOrganization());
        properties.setProperty("valid.destination.queue", "false");
        cloudlink.setCloudlinkProperties(properties);
        cloudlink.setEnableMessageListener(config.isEnableMessageListener());
        return cloudlink;
    }
}
